<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentRate.class.php, $Author:  $ */



/** Rate user component
 *
 * Parameters:
 *  1. oUser (required) - user that will be rate
 *  2. oRater (required) - user who rates
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentRate.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentRate extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
		App::membersOnly();

	    $bDisabled = App::getSetting('section_rate');
	    if ($bDisabled)
	    {
	        return App::format('Mod_Account.section_disabled');
	    }

	    $oSrvRate = &$this->_oModule->getService('Rate');
	    /* @var $oSrvRate PhpFox_Mod_Account_ServiceRate */

	    $oSrvSec = $this->_oModule->getService('Security');
	    /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */

	    $oReq = &App::getRequest();

	    $oAcc = &$this->_oModule->getItem('Account');
	    /* @var $oAcc PhpFox_Mod_Account_ItemAccount */
	    if (!$oAcc->load($oReq->getInt('id', 0)))
	    {
	        return App::format('Mod_Account.no_such_user');
	    }

	    $oRater = &$oSrvSec->getCurrentUser();
	    /* @var $oRater PhpFox_Mod_Account_ItemAccount */
	    assert($oRater != null);

	    if (! $bDisabled)
	    {
    	    // processing
            switch($oReq->getAction())
            {
                case 'rate_user':
                    $oSrvRate->addRate($oRater, $oAcc, $oReq->getInt('rating'));
                    $oUrl = &App::getUrl();
                    $oUrl->setParam('a', 1);
                    App::forward($oUrl->getUrl());
    				break;
            }
	    }

	    $oTpl = &$this->_oModule->getTemplate();
        if ($bDisabled)
        {
    		$oTpl-> assignSrc(array(
    		    'bDisabled'        => $bDisabled,
            ));
        }
        else
        {
    		$oTpl-> assignSrc(array(
    		    'aUser'        => $oAcc->aData,
        		'aRateInfo'    => $oSrvRate->getRateInfo($oAcc),
    		    'bIsRated'     => $oSrvRate->isRated($oRater, $oAcc),
    		    'sUserPicPath' => App::getParam('user.pic.url'),
    		));
        }
		$srcHtml = $oTpl->fetch('Rate.html');
		return $srcHtml;
	}

}
?>